<template>
	<div></div>
</template>
<script>
    import {isLogin,showToast} from '@/utils/handleLogin'
	export default {
		data () {
            return {}
		},
		methods: {
		    async load () {
		      let that = this 
		      let params = {
		                  order_id: that.$root.$mp.query.id
		                }
		                console.log(params)
		      that.$_util.ajax.post('https://guo-a.com/mapi/pay/pay?token=' + that.$store.state.Token,params).then((res) => {
		      	console.log(res)
                if(res.code === 200){
                    wx.requestPayment({
	                    'timeStamp': res.data.timeStamp,
	                    'nonceStr': res.data.nonceStr,
	                    'package': res.data.package,
	                    'signType': res.data.signType,
	                    'paySign': res.data.paySign,
	                    'success': function(dd){
	                    	if(dd.errMsg == "requestPayment:ok"){
	                    		// 调用支付成功
                               that.bindNavigateTo('/pages/myOrder/main')
	                    	}else if(dd.errMsg == 'requestPayment:cancel'){
	                    		// 用户取消支付
	                    	}
                            
	                    },
	                    'fail': function(dd){
	                    	wx.navigateBack()
	                    	return false
	                    },
	                    'complete': function(dd){

	                    }
                    })
	            }
		      })
		    },
		    /**
		     * 路由跳转
		     */
		    bindNavigateTo (url) {
		        wx.navigateTo({
		          url
		        })
		    },
		    bindSwitchTab (url) {
		        wx.switchTab({
		          url
		        })
		    }
		},
		onShow () {
		  	isLogin(() => {
		  		/*如果没有订单ID传入 则跳转到上一页*/
		  		if (!this.$root.$mp.query.hasOwnProperty('id')) {
                    wx.navigateBack()
                }
		  		this.load()
		  	})
		},
		mounted () {
		    
		}
	}
</script>